<template lang="">
    <div>
        展示所有资源
        <van-checkbox-group v-model="ids">
                <van-checkbox :name="i.id" v-for='i in resourcelist'>{{i.name}}</van-checkbox>
              </van-checkbox-group>
        <van-button @click='add'>添加</van-button>
    </div>
</template>
<script>
export default {
    data(){
        return{
            roleid:this.$route.query.id,
            resourcelist:[],
            ids:[]
        }
    },
    methods: {
        getresource(){
            this.axios.get('resourceM').then(res=>{
                this.resourcelist = res.data.list
                this.getResByid()
            })
        },
        add(){
            this.axios.post('setresource',{'roleid':this.roleid,'ids':this.ids}).then(res=>{
                if(res.data.code == 200){
                    alert('添加成功')
                }
            })
        },
        //查询此角色对应的资源ids
        getResByid(){
            this.axios.get('resourceM?id='+this.roleid).then(res=>{
                this.ids = res.data.list
            })
        }
    },
    mounted() {
        this.getresource()
    },
}
</script>
<style lang="">
    
</style>